package cn.fl.relationmap.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.relationmap.service.IRmEmployeeBscInfoService;
import cn.fl.relationmap.vo.EmployeeListRespVO;
import cn.fl.system.constant.SysLogConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;

import tc.relationmap.facade.relationmap.employee.condition.RmEmployeeBscInfoQC;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;

/**
 * @Description: 员工基本信息表 控制层
 */
@Controller
@RequestMapping("/relationmap/employee/rmemployeebscinfo")
public class RmEmployeeBscInfoController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(RmEmployeeBscInfoController.class);

	/**
	 * RmEmployeeBscInfo 服务层BEAN
	 */
	@Autowired
	private IRmEmployeeBscInfoService rmEmployeeBscInfoService;

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public String  toListPage() {
		return "relationmap/employee/employeeList";
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "initList", "加载列表页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		RmEmployeeBscInfoQC qc = new RmEmployeeBscInfoQC();
		page.setCondition(qc);

		Pager pager= rmEmployeeBscInfoService.searchListPage(page);
		List<EmployeeListRespVO> list = (List<EmployeeListRespVO>) pager.getResultList();
		ListPageVO<EmployeeListRespVO> listPage = new ListPageVO<EmployeeListRespVO>(list, pager.getTotalCount());
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "initList", "加载列表页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}

	@RequestMapping(value = "/addBatchByUpload.do", method = {RequestMethod.POST})
	@ResponseBody
	public DataResultVO addBatchByUpload(MultipartHttpServletRequest multipartRequest) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_FILE_UPLOAD_SUCC);
		try {
			rmEmployeeBscInfoService.addBatchByUpload(multipartRequest);
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "upload", "文件上传失败", CurrentThreadContext.getCurrentUserName(), ex);
		} catch (IllegalStateException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "upload", "文件上传失败,系统错误", CurrentThreadContext.getCurrentUserName(), ex);
		}
		return result;

	}
	
}

